package priv.demos.demo1.solution.main;

import com.alibaba.fastjson.JSON;
import com.payment.lc.fundacct.bean.FundDetailV4;

import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created on 2017/1/11.
 */
public class GenDBYields {

    public static void main(String[] args) throws Exception{
        BeanInfo beanInfo = Introspector.getBeanInfo(FundDetailV4.class);
        PropertyDescriptor[] propertyDescriptors = beanInfo
                .getPropertyDescriptors();

        for (PropertyDescriptor d : propertyDescriptors) {
            if (d.getReadMethod() != null && d.getWriteMethod() != null) {
                System.out.println(String.format(" statePo.%s(convert(detailV4.%s()));",
                        d.getWriteMethod().getName(), d.getReadMethod().getName()));
            }
        }
    }

    private static void scanFileGenYield() throws FileNotFoundException {
        File file = new File("D:/tmp/tmp2.txt");
        Scanner scanner = new Scanner(new FileInputStream(file));

        while (scanner.hasNext()) {
            String s1 = scanner.next();
            s1 = s1.substring(0, s1.length() - 1);
            String s2 = scanner.next();
            String str = "`%s`  DECIMAL (15, 4) DEFAULT NULL COMMENT '%s',";
            System.out.println(String.format(str, genYield(s1), s2));
        }

        scanner.close();
    }


    private static String genYield(String s) {
        StringBuffer result = new StringBuffer();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if ('A' <= c && c <= 'Z') {
                result.append("_").append(Character.toLowerCase(c));
            } else {
                result.append(c);
            }
        }
        return result.toString();
    }
}